package com.ccit.equip.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ccit.equip.mapper.OverhaulMapper;
import com.ccit.equip.service.OverhaulService;
import com.ccit.model.Overhaul;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
@Transactional(rollbackFor = Exception.class)
public class OverhaulServiceImpl extends ServiceImpl<OverhaulMapper, Overhaul> implements OverhaulService {

    @Autowired
    private OverhaulMapper overhaulMapper;


    @Override
    public List<Overhaul> listAllOverhaulRecord() {
        return overhaulMapper.listAllOverhaulRecord();
    }

    @Override
    public List<Overhaul> getByDynamic(Integer employee_id, String name) {
        String val = employee_id + "";
        QueryWrapper<Overhaul> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(StringUtils.isNotBlank(name), "name", name)
                .or()
                .like(StringUtils.isNotBlank(val), "employee_id", employee_id);
        //创建时间降序
        queryWrapper.orderByDesc("time");

        return overhaulMapper.selectList(queryWrapper);
    }

    @Override
    public Page<Overhaul> listOverhaul() {
        String sql = "select id from overhaul order by time";
        return null;
    }
}
